﻿using System.Collections.Generic;
using GraphProcessor;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Level + "/" + LevelEditorConst.Condition, typeof(LevelServiceGraph))]
    public class LevelServiceConditionNode : BaseNode
    {
        public override Color color => Color.yellow;
        [LevelServiceEditorCustomProperty("Co", "Condition表ID")]public int conditionID;
        // public List<int> conditionParam;
        
        [Input("last", false)] public LevelServiceEditor last;
        [Output("true", false)] public LevelServiceEditor execution;
        [Output("false", false)] public LevelServiceEditor vetoExecution;

        protected override void Process()
        {
            base.Process();
            if (this.last == null)
            {
                return;
            }
            var rServiceConfig = this.last.serviceConfig;
            if (rServiceConfig == null)
            {
                Debug.LogError($"条件必须依赖于服务存在,条件【{this.GetCustomName()}】后续内容被抛弃");
                return;
            }
            if (rServiceConfig.condition != null)
            {
                Debug.LogError($"每个服务只能有一个条件，条件【{this.GetCustomName()}】后续内容被抛弃");
                return;
            }
            rServiceConfig.condition = new EditorLevelServiceConditionConfig()
            {
                conditionID = this.conditionID,
            };
            this.execution = new LevelServiceEditor()
            {
                conditionType = 1,
                serviceConfig = rServiceConfig,
            };
            this.vetoExecution = new LevelServiceEditor()
            {
                conditionType = -1,
                serviceConfig = rServiceConfig,
            };
        }
    }
}